package com.hippoDocker.security.controller;

import com.hippoDocker.commons.entities.CommonResult;
import com.hippoDocker.security.pojo.dto.UmsMemberDTO;
import com.hippoDocker.security.service.LoginService;
import com.hippoDocker.security.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 会员表(UmsMember)表控制层
 *
 * @author makejava
 * @since 2022-07-26 15:52:10
 */
@RestController
@RequestMapping("/umsMember")
public class UmsMemberController {

    /**
     * 服务对象
     */
    @Resource
    private UmsMemberService umsMemberService;

    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public CommonResult login(@RequestBody UmsMemberDTO umsMemberDTO){
        return  loginService.login(umsMemberDTO);
    }

    @GetMapping("/logout")
    public CommonResult logout(){
        return loginService.logout();
    }

    @PostMapping("/selectAll")
    @PreAuthorize("hasAnyAuthority('pms:product:read1')")
    public CommonResult selectAll() {
        return umsMemberService.selectAll();
    }

    @GetMapping("/selectOne/{id}")
    @PreAuthorize("@expressionRoot.hasAuthority('pms:product:read')")//自定义权限校验(SPEL表达式使用@expressionRoot中的hasAuthority方法验证)
    public CommonResult selectOne(@PathVariable Long id) {
        return umsMemberService.selectOneById(id);
    }

    @GetMapping("/testCors")
    public CommonResult testCors() {
        return CommonResult.success("testCors");
    }
}

